package org.vincen.court.web;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.vincen.court.service.ReservationService;

public class ReservationQueryController extends AbstractController {

	private ReservationService reservationService;

	public void setReservationService(ReservationService reservationService) {
		this.reservationService = reservationService;
	}

	public ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String courtName = ServletRequestUtils.getStringParameter(request,
				"courtName");

		Map<String, Object> model = new HashMap<String, Object>();
		if (courtName != null) {
			model.put("courtName", courtName);
			model.put("reservations", reservationService.query(courtName));
		}
		return new ModelAndView("reservationQuery", model);
	}
}
